import request from '@/service/request';
import { IRole, IUser, roleList, rolePageList } from './types';

// 获取到角色分页信息
export function getAllPageRole(data: {
  roleDTO: {
    createNameList: Array<any>;
    inputContent: string;
    orderColum: string;
    orderType: string;
    pageNum: number;
    pageSize: number;
    roleNameList: Array<any>;
  };
}) {
  return request.post<rolePageList[]>({
    url: '/role/getPageRole',
    data,
    interceptors: {
      responseInterceptor(res: any): rolePageList[] {
        return res?.data;
      },
    },
  });
}

// 获取到角色分页信息
export function getRoleInfoById(data: { id: number }) {
  return request.get<rolePageList[]>({
    url: `/role/${data.id}`,
    data,
    interceptors: {
      responseInterceptor(res: any): rolePageList[] {
        return res?.data;
      },
    },
  });
}

// 获取到登录用户所在企业下的所有员工
export function requestUserByOrg() {
  return request.get<IUser[]>({
    url: '/user/getUserByOrg',
    interceptors: {
      responseInterceptor(res: any): IUser[] {
        return res?.data;
      },
    },
  });
}

// 添加角色
export function addRole(data: {
  rolePTO: {
    description: string;
    id: number;
    name: string;
    orgId: number;
    roleList: roleList[];
  };
}) {
  return request.post<IRole[]>({
    url: '/role/editRole',
    data,
    interceptors: {
      responseInterceptor(res: any): IRole[] {
        return res;
      },
    },
  });
}

// 获取所以角色信息
export function getAllRole() {
  return request.get<IRole[]>({
    url: '/role/getAllRoleByOrg',
    interceptors: {
      responseInterceptor(res: any): IRole[] {
        return res;
      },
    },
  });
}

// 获取所以角色信息
export function deleteRole(data: { isd: number[] }) {
  return request.post<roleList[]>({
    url: '/role/batchDeleteRole',
    data,
    interceptors: {
      responseInterceptor(res: any): roleList[] {
        return res;
      },
    },
  });
}

export default {};
